## FIGURE 1

## Read data

library(foreign)
library(ggplot2) 
library(stats)
library(gridExtra)
library(scales)
library(ggpubr)

nsadata <- read.dta("/Users/mariadellmuth/csos_by_rfmo.dta")

attach(nsadata)

## Define base for the graphs and store in object 'p'

p1 <- ggplot(subset(nsadata, RFMO=="CCAMLR"), aes(x=Year, y = csonum))   + xlab("") + ylab("") + ggtitle("CCAMLR") + geom_line(color='darkblue') + coord_fixed(ratio = .5, ylim = c(0,110), expand = TRUE, xlim=c(1980,2014))  +  theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title = element_text(size=8, margin = margin(b = -20)),    axis.title.x = element_text(margin = margin(t = -40)),    axis.title.y = element_text(margin = margin(r = -10))) 
p2 <- ggplot(subset(nsadata, RFMO=="CCSBT"), aes(x=Year, y = csonum))   + xlab("") + ylab("") + ggtitle("CCSBT") + geom_line(color='darkblue') + coord_fixed(ratio = .5, ylim = c(0,110), expand = TRUE, xlim=c(1980,2014))  +  theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title = element_text(size=8, margin = margin(b = -20)),    axis.title.x = element_text(margin = margin(t = -40)),    axis.title.y = element_text(margin = margin(r = -10))) 
p3 <- ggplot(subset(nsadata, RFMO=="IATTC"), aes(x=Year, y = csonum))   + xlab("") + ylab("") + ggtitle("IATTC") + geom_line(color='darkblue') + coord_fixed(ratio = .5, ylim = c(0,110), expand = TRUE, xlim=c(1980,2014))  +  theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title = element_text(size=8, margin = margin(b = -20)),    axis.title.x = element_text(margin = margin(t = -40)),    axis.title.y = element_text(margin = margin(r = -10))) 
p4 <- ggplot(subset(nsadata, RFMO=="ICCAT"), aes(x=Year, y = csonum))   + xlab("") + ylab("") + ggtitle("ICCAT") + geom_line(color='darkblue') + coord_fixed(ratio = .5, ylim = c(0,110), expand = TRUE, xlim=c(1980,2014))  +  theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title = element_text(size=8, margin = margin(b = -20)),    axis.title.x = element_text(margin = margin(t = -40)),    axis.title.y = element_text(margin = margin(r = -10))) 
p5 <- ggplot(subset(nsadata, RFMO=="IOTC"), aes(x=Year, y = csonum))   + xlab("") + ylab("") + ggtitle("IOTC") + geom_line(color='darkblue') + coord_fixed(ratio = .5, ylim = c(0,110), expand = TRUE, xlim=c(1980,2014))  +  theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title = element_text(size=8, margin = margin(b = -20)),    axis.title.x = element_text(margin = margin(t = -40)),    axis.title.y = element_text(margin = margin(r = -10))) 
p6 <- ggplot(subset(nsadata, RFMO=="NAFO"), aes(x=Year, y = csonum))   + xlab("") + ylab("") + ggtitle("NAFO") + geom_line(color='darkblue') + coord_fixed(ratio = .5, ylim = c(0,110), expand = TRUE, xlim=c(1980,2014))  +  theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title = element_text(size=8, margin = margin(b = -20)),    axis.title.x = element_text(margin = margin(t = -40)),    axis.title.y = element_text(margin = margin(r = -10))) 
p7 <- ggplot(subset(nsadata, RFMO=="WCPFC"), aes(x=Year, y = csonum))   + xlab("") + ylab("") + ggtitle("WCPFC") + geom_line(color='darkblue') + coord_fixed(ratio = .5, ylim = c(0,110), expand = TRUE, xlim=c(1980,2014))  +  theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title = element_text(size=8, margin = margin(b = -20)),    axis.title.x = element_text(margin = margin(t = -40)),    axis.title.y = element_text(margin = margin(r = -10))) 

# Create high resolution plot with nine panels, combining the above plots

plots <- arrangeGrob(p1, p2, p3, p4, p5, p6, p7, nrow=3,
                     bottom = textGrob("",
                       gp = gpar(fontface = 3, fontsize = 9),
                       hjust = 1,
                       x = 1
                     )
)
ph <- sum(plots$heights)

require("grid")

tiff('fig1.tiff', units="in", width=5, height=8, res=300)
grid.arrange(arrangeGrob(plots, heights = unit.c(unit(10, "null"), ph), left = textGrob("Number of NGOs", rot = 90, vjust = 1, hjust=0, gp = gpar(fontsize = 10)))) 
dev.off()



## FIGURE 2

## Read data

library(foreign)

nsadata <- read.dta("/Users/mariadellmuth/nsa_type_by_rfmo.dta")

attach(nsadata)

## Define base for the graphs and store in object 'p'

library(ggplot2) 
library(stats)
library(gridExtra)
library(scales)
library(ggpubr)

p1 <- ggplot(subset(nsadata, RFMO=="CCAMLR"),aes(Year, Percent,fill=Type))+geom_area(aes(colour=Type),position="stack")+  scale_fill_brewer(palette="Blues") + theme_grey(base_size = 9)  + theme(legend.position = "bottom") + labs(title = "CCAMLR", x = "", y = "") + scale_y_continuous(labels = percent)+ coord_cartesian(xlim=c(1980,2015)) 
p2 <- ggplot(subset(nsadata, RFMO=="CCSBT"),aes(Year, Percent,fill=Type))+geom_area(aes(colour=Type),position="stack")+  scale_fill_brewer(palette="Blues")  + theme_grey(base_size = 9)  + theme(legend.position = "bottom") + labs(title = "CCSBT", x = "", y = "") + scale_y_continuous(labels = percent) + coord_cartesian(xlim=c(1980,2015))
p3 <- ggplot(subset(nsadata, RFMO=="IATTC"),aes(Year, Percent,fill=Type))+geom_area(aes(colour=Type),position="stack")+  scale_fill_brewer(palette="Blues") + theme_grey(base_size = 9)  + theme(legend.position = "bottom") + labs(title = "IATTC", x = "", y = "") + scale_y_continuous(labels = percent)+ coord_cartesian(xlim=c(1980,2015))
p4 <-   ggplot(subset(nsadata, RFMO=="ICCAT"),aes(Year, Percent,fill=Type))+geom_area(aes(colour=Type),position="stack")+  scale_fill_brewer(palette="Blues") + theme_grey(base_size = 9)  + theme(legend.position = "bottom") + labs(title = "ICCAT", x = "", y = "Density of CSOs") + scale_y_continuous(labels = percent) + coord_cartesian(xlim=c(1980,2015))
p5 <- ggplot(subset(nsadata, RFMO=="IOTC"),aes(Year, Percent,fill=Type))+geom_area(aes(colour=Type),position="stack")+  scale_fill_brewer(palette="Blues") + theme_grey(base_size = 9)  + theme(legend.position = "bottom") + labs(title = "IOTC", x = "", y = "") + scale_y_continuous(labels = percent) + coord_cartesian(xlim=c(1980,2015))
p6 <- ggplot(subset(nsadata, RFMO=="NAFO"),aes(Year, Percent,fill=Type))+geom_area(aes(colour=Type),position="stack")+  scale_fill_brewer(palette="Blues") + theme_grey(base_size = 9)  + theme(legend.position = "bottom") + labs(title = "NAFO", x = "", y = "") + scale_y_continuous(labels = percent) + coord_cartesian(xlim=c(1980,2015))
p7 <- ggplot(subset(nsadata, RFMO=="WCPFC"),aes(Year, Percent,fill=Type))+geom_area(aes(colour=Type),position="stack")+ scale_fill_brewer(palette="Blues") + theme_grey(base_size = 9)  + theme(legend.position = "bottom") + labs(title = "WCPFC", x = "", y = "") + scale_y_continuous(labels = percent) + coord_cartesian(xlim=c(1980,2015))


# Create high resolution plot with nine panels, combining the above plots

plots <- arrangeGrob(p1, p2, p3, p4, p5, p6, p7, nrow=3)
ph <- sum(plots$heights)

require("grid")

tiff('fig2.tiff', units="in", width=7, height=7, res=300)
ggarrange(p1, p2, p3, p4, p5, p6, p7, ncol=3, nrow=3, common.legend = TRUE, legend="bottom")
dev.off()



## FIGURE 3

## Read data

library(foreign)

nsadata <- read.dta("/Users/mariadellmuth/Dropbox/nsa-all.dta")

attach(nsadata)

## Define base for the graphs and store in object 'p'

library(ggplot2) 
library(stats)
library(gridExtra)

# First plot
p1 <-   ggplot(subset(nsadata, rfmonum=="CCAMLR"), aes(x=year, y = ffmsy, colour=speciesnum)) + scale_x_continuous(limits = c(1980, 2015)) + scale_colour_continuous(guide = FALSE) + xlab("") + ylab("") + geom_point(alpha=0.09) + ggtitle("CCAMLR") + stat_smooth(method = "loess", formula = y ~ x, size = 0.5) + coord_fixed(ratio = 4.5, ylim = c(-1,7), expand = TRUE)  +  theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title = element_text(size=8, margin = margin(b = -20)),    axis.title.x = element_text(margin = margin(t = -40)),    axis.title.y = element_text(margin = margin(r = -10))) + geom_hline(aes(yintercept=1), color="blue4",size=0.5) 

# Second plot
p2 <- ggplot(subset(nsadata, rfmonum=="CCSBT"), aes(x=year, y = ffmsy, colour=speciesnum))  + scale_colour_continuous(guide = FALSE) + xlab("") + ylab("") + geom_point(alpha=0.07) + ggtitle("CCSBT") + stat_smooth(method = "loess", formula = y ~ x, size = 0.5) + coord_fixed(ratio = 4.5, ylim = c(-1,7), expand = TRUE)  +   theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title = element_text(size=8, margin = margin(b = -20)),    axis.title.x = element_text(margin = margin(t = -40)),    axis.title.y = element_text(margin = margin(r = -10))) + geom_hline(aes(yintercept=1), color="blue4",size=0.5) 

# Third plot
p3 <- ggplot(subset(nsadata, rfmonum=="IATTC"), aes(x=year, y = ffmsy, colour=speciesnum))  + scale_colour_continuous(guide = FALSE) + xlab("") + ylab("") + geom_point(alpha=0.07) + ggtitle("IATTC") + stat_smooth(method = "loess", formula = y ~ x, size = 0.5) + coord_fixed(ratio = 4.5, ylim = c(-1,7), expand = TRUE) +  theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title = element_text(size=8, margin = margin(b = -20)),    axis.title.x = element_text(margin = margin(t = -40)),    axis.title.y = element_text(margin = margin(r = -10))) + geom_hline(aes(yintercept=1), color="blue4",size=0.5) 

# Fourth plot
p4 <- ggplot(subset(nsadata, rfmonum=="ICCAT"), aes(x=year, y = ffmsy, colour=speciesnum))  + scale_colour_continuous(guide = FALSE) + xlab("") + ylab("") + geom_point(alpha=0.07) + ggtitle("ICCAT") + stat_smooth(method = "loess", formula = y ~ x, size = 0.5) + coord_fixed(ratio = 4.5, ylim = c(-1,7), expand = TRUE) + theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title = element_text(size=8, margin = margin(b = -20)),    axis.title.x = element_text(margin = margin(t = -40)),    axis.title.y = element_text(margin = margin(r = -10))) + geom_hline(aes(yintercept=1), color="blue4",size=0.5) 

# Fifth plot
p5 <- ggplot(subset(nsadata, rfmonum=="IOTC"), aes(x=year, y = ffmsy, colour=speciesnum))  + scale_colour_continuous(guide = FALSE) + xlab("") + ylab("")  + geom_point(alpha=0.07) + ggtitle("IOTC") + stat_smooth(method = "loess", formula = y ~ x, size = 0.5) + coord_fixed(ratio = 4.5, ylim = c(-1,7), expand = TRUE) + theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title = element_text(size=8, margin = margin(b = -20)),    axis.title.x = element_text(margin = margin(t = -40)),    axis.title.y = element_text(margin = margin(r = -10))) + geom_hline(aes(yintercept=1), color="blue4",size=0.5) 

# Sixth plot
p6 <- ggplot(subset(nsadata, rfmonum=="NAFO"), aes(x=year, y = ffmsy, colour=speciesnum))  + scale_colour_continuous(guide = FALSE) + xlab("") + ylab("") + geom_point(alpha=0.07) + ggtitle("NAFO") + stat_smooth(method = "loess", formula = y ~ x, size = 0.5) + coord_fixed(ratio = 4.5, ylim = c(-1,7), expand = TRUE) + theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title = element_text(size=8, margin = margin(b = -20)),    axis.title.x = element_text(margin = margin(t = -40)),    axis.title.y = element_text(margin = margin(r = -10))) + geom_hline(aes(yintercept=1), color="blue4",size=0.5) 

# Seventh plot
p7 <- ggplot(subset(nsadata, rfmonum=="WCPFC"), aes(x=year, y = ffmsy, colour=speciesnum)) + scale_colour_continuous(guide = FALSE) + xlab("") + ylab("") + geom_point(alpha=0.07) + ggtitle("WCPFC") + stat_smooth(method = "loess", formula = y ~ x, size = 0.5) + coord_fixed(ratio = 4.5, ylim = c(-1,7), expand = TRUE) +  theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title =  element_text(size=8, margin = margin(b = -20)),    axis.title.x = element_text(margin = margin(t = -40)),    axis.title.y = element_text(margin = margin(r = -10)))  + geom_hline(aes(yintercept=1), color="blue4",size=0.5) 


# Create high resolution plot with nine panels, combining the above plots

plots <- arrangeGrob(p1, p2, p3, p4, p5, p6, p7, nrow=3,
                     bottom = textGrob("",
                                       gp = gpar(fontface = 3, fontsize = 9),
                                       hjust = 1,
                                       x = 1
                     )
)
ph <- sum(plots$heights)

require("grid")

tiff('fig3.tiff', units="in", width=5, height=6, res=300)
grid.arrange(arrangeGrob(plots, heights = unit.c(unit(10, "null"), ph), left = textGrob("F/Fmsy", rot = 90, vjust = 1, hjust=-1, gp = gpar(fontsize = 10)))) 
dev.off()
